package com.xjc.business.controller.colladmin;

import com.xjc.business.entity.po.classadmin.ClassAdminStayBedApplyOpera;
import com.xjc.business.entity.vo.PageVo;
import com.xjc.business.entity.vo.classadmin.ClassStayApplyVo;
import com.xjc.business.service.StudentStayBedApplysService;
import com.xjc.system.constants.MyConstants;
import com.xjc.system.exception.MyException;
import com.xjc.system.result.Result;
import com.xjc.system.result.ResultCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 徐锦程
 * 时间:2025-02-08 17:38
 */
@RestController
@RequestMapping("/college_admin/stay_apply")
public class CollegeStayBedApplyController {

    @Autowired
    StudentStayBedApplysService studentStayBedApplysService;

    /**
     * 获取学生留宿申请列表
     * @param pageSize 每页显示条数
     * @param currentPage 当前页
     * @param collegeAdminId 辅导员id
     * @param status 状态
     * @param stuName 学生姓名
     * @return Result
     */
    @RequestMapping("/page/{pageSize}/{currentPage}")
    public Result<PageVo<ClassStayApplyVo>> getStayApplyList(
            @PathVariable(value = "pageSize",required = false) Integer pageSize,
            @PathVariable(value = "currentPage",required = false) Integer currentPage,
            Integer collegeAdminId,
            Integer status,
            String stuName
    ){

        if(pageSize == null || pageSize <= 0){
            pageSize = 10;
        }
        if(currentPage == null || currentPage <= 0){
            currentPage = 1;
        }

        if(status == null){
            status = -1;
        }

        if(stuName == null){
            stuName = "";
        }

        if(collegeAdminId == null){
            throw new MyException(ResultCode.SUCCESS.getCode(), MyConstants.PARAM_MISSING);
        }

        return studentStayBedApplysService.getStayApplyPage2(pageSize,currentPage,collegeAdminId,status,stuName);

    }

    /**
     * 辅导员审批留宿申请
     * @param classAdminStayBedApplyOpera 审批意见
     * @return Result
     */
    @PostMapping("/opera")
    public Result<String> leaveApplyOpera(@RequestBody(required = false) ClassAdminStayBedApplyOpera classAdminStayBedApplyOpera){
        if(classAdminStayBedApplyOpera == null){
            throw new MyException(ResultCode.SUCCESS.getCode(), MyConstants.PARAM_MISSING);
        }

        return studentStayBedApplysService.leaveApplyOpera(classAdminStayBedApplyOpera);
    }
    /**
     * 学院管理员审批留宿申请
     * @param classAdminStayBedApplyOpera 审批意见
     * @return Result
     */
    @PostMapping("/opera2")
    public Result<String> leaveApplyOpera2(@RequestBody(required = false) ClassAdminStayBedApplyOpera classAdminStayBedApplyOpera){
        if(classAdminStayBedApplyOpera == null){
            throw new MyException(ResultCode.SUCCESS.getCode(), MyConstants.PARAM_MISSING);
        }

        return studentStayBedApplysService.leaveApplyOpera2(classAdminStayBedApplyOpera);
    }
}